Home:ALL Converter>"Specified method is not supported" in Entity Framework

"Specified method is not supported" in Entity Framework

Ask Time:2012-07-31T14:51:04         Author:GowthamanSS

Json Formatter

This is my entity class:

public partial class NerdDinnerEntities : ObjectContext
{
    public NerdDinnerEntities(string connectionString)
        : base(connectionString, "NerdDinnerEntities")
    {
        try
        {
            ObjectContext oc = new ObjectContext(connectionString);

           oc.Connection.ChangeDatabase("NERDDINNER1");
           oc.AcceptAllChanges();
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
        catch (Exception ex) { }
    }

    partial void OnContextCreated();

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public ObjectSet<Dinner> Dinners
    {
        get
        {
            if ((_Dinners == null))
            {
                _Dinners = base.CreateObjectSet<Dinner>("Dinners");
            }
            return _Dinners;
        }
    }
    private ObjectSet<Dinner> _Dinners;

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public ObjectSet<RSVP> RSVPs
    {
        get
        {
            if ((_RSVPs == null))
            {
                _RSVPs = base.CreateObjectSet<RSVP>("RSVPs");
            }
            return _RSVPs;
        }
    }

    private ObjectSet<RSVP> _RSVPs;

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public ObjectSet<sysdiagram> sysdiagrams
    {
        get
        {
            if ((_sysdiagrams == null))
            {
                _sysdiagrams = base.CreateObjectSet<sysdiagram>("sysdiagrams");
            }
            return _sysdiagrams;
        }
    }

    private ObjectSet<sysdiagram> _sysdiagrams;

    /// <summary>
    /// Deprecated Method for adding a new object to the Dinners EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
    /// </summary>
    public void AddToDinners(Dinner dinner)
    {
        base.AddObject("Dinners", dinner);
    }

    /// <summary>
    /// Deprecated Method for adding a new object to the RSVPs EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
    /// </summary>
    public void AddToRSVPs(RSVP rSVP)
    {
        base.AddObject("RSVPs", rSVP);
    }

    /// <summary>
    /// Deprecated Method for adding a new object to the sysdiagrams EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
    /// </summary>
    public void AddTosysdiagrams(sysdiagram sysdiagram)
    {
        base.AddObject("sysdiagrams", sysdiagram);
    }
}

and these is my web.config file as

<add name="NerdDinnerEntities" connectionString="metadata=res://*/Models.NerdDinner.csdl|res://*/Models.NerdDinner.ssdl|res://*/Models.NerdDinner.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=@;Database=NERDDINNER;User ID=@;Password=@@@;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClients" />

and i am getting error:

Specified method is not supported

in this line:

oc.Connection.ChangeDatabase("NERDDINNER1");

Author:GowthamanSS,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11734641/specified-method-is-not-supported-in-entity-framework
Gerard Sexton :

If you look up the docs at MSDN you will see that the method literally is not supported. It must be a placeholder for future improvements or something.\n\nTo expand for those who do want to change the database at runtime: \n\n1.Create an entry in your settings to use in-place of the default in the app.config. Pull out the specifics, like Username, password, catalog name (database name), server etc into other settings entries. \n\n<Setting Name=\"EntityConnectionString2\" Type=\"System.String\" Scope=\"Application\">\n <Value Profile=\"(Default)\">metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=\"data source={0};initial catalog={1};persist security info=True;user id={2};password={3};encrypt=True;trustservercertificate=True;multipleactiveresultsets=True;App=EntityFramework\"</Value>\n</Setting>\n\n\nPlease note the {0}..{3} entries & that this connection string is not the whole configuration/connectionStrings/add entry in the app.config \n\n2.Use one of the overloaded constructors for the EF Database that accepts a connection string. \n\nvar settings = Properties.Settings.Default; \nstring constring = string.Format(settings.EntityConnectionString2, settings.Server, settings.Database, settings.User, settings.Password);\nNerdDinnerEntities db = new NerdDinnerEntities (constring); \n\n\n3.To change at runtime you can create a different object in the same manner with a different catalog name, or dispose and recreate the db object with a different catalog name. ",
2012-07-31T06:56:24
yy